package com.neusoft.elmboot.mapper;

import com.neusoft.elmboot.po.Business;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface FavoriteBusinessMapper {

    @Insert("INSERT INTO favorite_business (userId, businessId) VALUES (#{userId}, #{businessId})")
    int addFavorite(@Param("userId") String userId, @Param("businessId") String businessId);

    @Delete("DELETE FROM favorite_business WHERE userId = #{userId} AND businessId = #{businessId}")
    int removeFavorite(@Param("userId") String userId, @Param("businessId") String businessId);

    @Select("SELECT COUNT(*) FROM favorite_business WHERE userId = #{userId} AND businessId = #{businessId}")
    int exists(@Param("userId") String userId, @Param("businessId") String businessId);

    @Select("SELECT b.* FROM favorite_business f JOIN business b ON f.businessId = b.businessId WHERE f.userId = #{userId} ORDER BY f.createTime DESC")
    List<Business> listFavoritesByUserId(@Param("userId") String userId);
}
